/* 
 * File:   openFiles.h
 * Author: Juan Carlos Fernández Toledano
 * Created on 22 de noviembre de 2011, 18:19
 */
#ifndef OPENFILES_H
#define	OPENFILES_H

#include "objetos.h"


void importBinary (ifstream *filein, particula *part,  parametros *param)
{
    double x,y,z,vx,vy,vz,diam,fx,fy,fz;
    double lx,ly,lz;
    double t;
    int npart,nacc;
    (*filein).read(reinterpret_cast<char *>(&t), sizeof(double));
    (*filein).read(reinterpret_cast<char *>(&nacc), sizeof(int));
    (*filein).read(reinterpret_cast<char *>(&npart), sizeof(int));
    (*filein).read(reinterpret_cast<char *>(&lx), sizeof(double));
    (*filein).read(reinterpret_cast<char *>(&ly), sizeof(double));
    (*filein).read(reinterpret_cast<char *>(&lz), sizeof(double));
    param->t=t;
    param->lbox[0]=lx;
    param->lbox[1]=ly;
    param->lbox[2]=lz;
    param->nacc=nacc;
    param->npart=npart;
    for (int j=0;j<npart;j++)
    {
        (*filein).read(reinterpret_cast<char *>(&x), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&y), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&z), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&vx), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&vy), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&vz), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&fx), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&fy), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&fz), sizeof(double));
        (*filein).read(reinterpret_cast<char *>(&diam), sizeof(double));
        part[j].pos[0]=x;
        part[j].pos[1]=y;
        part[j].pos[2]=z;

        part[j].vel[0]=vx;
        part[j].vel[1]=vy;
        part[j].vel[2]=vz;
        part[j].diameter=diam;
        part[j].mass=pow(part[j].diameter,3.0);
    }

    param->vol=(param->lbox[0])*(param->lbox[1])*(param->lbox[2]);

}



#endif	/* OPENFILES_H */

